$(document).ready(function () {
    initTTableData();

    /**
     * 刷新页面
     */
    function initTTableData() {
        $.ajax(
            {
                type: 'get',
                url: 'clazz/list',
                success: function (tableData) {
                    $('#tbody_clazz').html(tableData);
                }
            });
        //新增
        /*  $.ajax({
              type:'post',
              url: 'clazz'
          })
          //修改
          $.ajax({
              type:'put',
              url: 'clazz'
          })
          //删除
          $.ajax({
              type:'delete',
              url:'clazz/'+rowId,
          });*/

    }

    /**
     * 增弹窗
     */
    $('#search_form').off('click', '#newAdd').on('click', '#newAdd', function () {
        $.ajax({
            url: "clazz/goadd",
            type: 'post',
            success: function (htmldata) {
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['420px', '240px'], //宽高
                    content: htmldata
                });
            }
        });
        return false;
    });

    /**
     * 执行增
     */
    $(document).off('click', '#sub_doadd').on('click', '#sub_doadd', function () {
        $.ajax({
            url: "clazz",
            type: 'post',
            data: $("#doaddform").serialize(),
            success: function (htmldata) {
                initTTableData();
                layer.close(layer.index)
            }
        });
        return false;
    });

    /**
     * 删除
     */
    $(document).off('click', ".a_delete").on('click', ".a_delete", function () {
        var href = $(this).attr('href');
        console.log("sedrdwefwefwfasihoasjikasjikjidk")
        if (confirm("确定删除?")) {
            //点击确定后操作
            $.ajax({
                type: 'delete',
                url: href,
                success: function () {
                    initTTableData();
                }
            });
        }
        return false;
    });


    /**
     * 去修改
     */
    $(document).off('click', ".a_edit").on('click', ".a_edit", function () {
        var href = $(this).attr('href');
        //点击确定后操作
        $.ajax({
            url: href,
            type: 'post',
            success: function (htmldata) {
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['420px', '240px'], //宽高
                    content: htmldata
                });
            }
        });
        return false;
    });
    /**
     * 执行
     */
    $(document).off('click', "#sub_edit").on('click',
        "#sub_edit", function () {
            console.log("ssss")
            $.ajax({
                url: "clazz",
                type: 'PUT',
                data: $("#form_edit").serialize(),
                success: function (htmldata) {
                    layer.close(layer.index)
                    initTTableData();
                }
            });
            return false;
        })


});